home *** CD-ROM | disk | FTP | other *** search
/ Nautilus 1992 July / Nautilus-3-8 / Nautilus-3-8.bin / Tools & Utilities / Techy Stuff / Source ƒ / egrep-1.5 / grep-src / dirent.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-25  |  1.4 KB  |  75 lines

  1. /* This file contains a very incomplete implementation of the
  2.    UNIX dirent routines for THINK C - Mac.
  3.    
  4.    This code is crap.
  5.    
  6.    You can only open the current directory.
  7. */
  8.  
  9. /* Do NOT have the THINK C MacHeaders option checked-- include
  10.    manually */
  11. #include <MacHeaders>
  12.  
  13. #include <Pascal.h>
  14. #include <stdlib.h>
  15.  
  16. #include "dirent.h"
  17. #include "string.h"
  18.  
  19. #ifndef NULL
  20. #define NULL 0;
  21. #endif
  22.  
  23. static HFileInfo        myCPB;        /* for the PBGetCatInfo call */
  24. static short int theIndex;
  25. static long int dirIDToSearch;
  26. static struct dirent mydirent;
  27.  
  28.  
  29. /* Only works for ".".  And only one active call at a time */
  30. DIR *opendir(filename)
  31.    char *filename;
  32. {
  33.     if (strcmp(filename, ".") != 0) {
  34.        SysBeep(1);
  35.        return (void *) 0;
  36.     }
  37.     
  38.     mydirent.d_fileno = 1L;
  39.     *mydirent.d_name = '\0';
  40.     myCPB.ioNamePtr = (void *) CtoPstr(mydirent.d_name);
  41.     myCPB.ioVRefNum = 0;
  42.     dirIDToSearch = 0L;    /* Current one */
  43.     theIndex = 1;
  44.     return (DIR *)11;
  45.  
  46. }
  47.  
  48. closedir(dirp)
  49.    DIR *dirp;
  50. {
  51.  
  52. }
  53.  
  54. struct dirent *readdir(dirp)
  55.    DIR *dirp;
  56. {
  57.    OSErr err;
  58.    
  59.    myCPB.ioFDirIndex= theIndex;        /* set up the index */
  60.  
  61.    /* we need to do this every time through, since GetCatInfo returns 
  62.       ioFlNum in this field*/
  63.    myCPB.ioDirID= dirIDToSearch;    
  64.  
  65.    err= PBGetCatInfo(&myCPB,false);
  66.  
  67.    if (err != noErr) return NULL;
  68.  
  69.    PtoCstr(mydirent.d_name);
  70.    mydirent.d_namlen = strlen(mydirent.d_name);
  71.  
  72.    theIndex++;
  73.    return &mydirent;
  74. }
  75.